package com.kaizzi.data.ppt;

import com.fasterxml.jackson.databind.JsonNode;
import com.kaizzi.data.jdl.service.LogService;
import com.kaizzi.data.ppt.template.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xslf.usermodel.XSLFChart;
import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Kzen
 * @Description description
 * @date 2020/9/27
 */
@Component
@Slf4j
public class JdlReplaceData {

    @Resource
    private LogService logService;

    @Resource
    private Template1 template1;
    @Resource
    private Template4 template4;
    @Resource
    private Template7 template7;
    @Resource
    private Template8 template8;
    @Resource
    private Template9 template9;
    @Resource
    private Template10 template10;
    @Resource
    private Template11 template11;
    @Resource
    private Template12 template12;
    @Resource
    private Template14 template14;
    @Resource
    private Template15 template15;
    @Resource
    private Template17 template17;
    @Resource
    private Template18 template18;
    @Resource
    private Template20 template20;
    @Resource
    private Template21 template21;
    @Resource
    private Template22 template22;
    @Resource
    private Template24 template24;
    @Resource
    private Template25 template25;
    @Resource
    private Template27 template27;
    @Resource
    private Template29 template29;
    @Resource
    private Template30 template30;
    @Resource
    private Template32 template32;
    @Resource
    private Template34 template34;
    @Resource
    private Template35 template35;
    @Resource
    private Template37 template37;
    @Resource
    private Template38 template38;
    @Resource
    private Template39 template39;
    @Resource
    private Template41 template41;
    @Resource
    private Template42 template42;
    @Resource
    private Template45 template45;
    @Resource
    private Template46 template46;

    //文字替换
    public void replaceText(int page, List<XSLFTextParagraph> textParagraphs,JsonNode pageData) {

        try {
            switch (page+1){
                case 1:
                    template1.text(textParagraphs,pageData);
                    break;
                case 4:
                    template4.text(textParagraphs,pageData);
                    break;
                case 7:
                    template7.text(textParagraphs,pageData);
                    break;
                case 8:
                    template8.text(textParagraphs,pageData);
                    break;
                case 9:
                    template9.text(textParagraphs,pageData);
                    break;
                case 10:
                    template10.text(textParagraphs,pageData);
                    break;
                case 11:
                    template11.text(textParagraphs,pageData);
                    break;
                case 12:
                    template12.text(textParagraphs,pageData);
                    break;
                case 14:
                    template14.text(textParagraphs,pageData);
                    break;
                case 15:
                    template15.text(textParagraphs,pageData);
                    break;
                case 17:
                    template17.text(textParagraphs,pageData);
                    break;
                case 18:
                    template18.text(textParagraphs,pageData);
                    break;
                case 20:
                    template20.text(textParagraphs,pageData);
                    break;
                case 21:
                    template21.text(textParagraphs,pageData);
                    break;
                case 22:
                    template22.text(textParagraphs,pageData);
                    break;
                case 24:
                    template24.text(textParagraphs,pageData);
                    break;
                case 25:
                    template25.text(textParagraphs,pageData);
                    break;
                case 27:
                    template27.text(textParagraphs, pageData);
                    break;
                case 29:
                    template29.text(textParagraphs,pageData);
                    break;
                case 30:
                    template30.text(textParagraphs,pageData);
                    break;
                case 32:
                    template32.text(textParagraphs,pageData);
                    break;
                case 34:
                    template34.text(textParagraphs,pageData);
                    break;
                case 35:
                    template35.text(textParagraphs,pageData);
                    break;
                case 37:
                    template37.text(textParagraphs,pageData);
                    break;
                case 38:
                    template38.text(textParagraphs,pageData);
                    break;
                case 39:
                    template39.text(textParagraphs,pageData);
                    break;
                case 41:
                    template41.text(textParagraphs,pageData);
                    break;
                case 42:
                    template42.text(textParagraphs,pageData);
                    break;
                case 45:
                    template45.text(textParagraphs,pageData);
                    break;
                case 46:
                    template46.text(textParagraphs,pageData);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            logService.setDataLogStatus("ppt-error");
            log.error("text 替换异常，异常页码:{},text Exception:{}",page+1,e);
        }
    }

    public void replaceSimpleShape(int page, int red, XSLFShape shape, JsonNode data) {
        try {
            switch (page+1){
                case 7:
                    template7.simpleShape(red,shape,data);
                    break;
                case 8:
                    template8.simpleShape(red,shape,data);
                    break;
                case 35:
                    template35.simpleShape(red,shape,data);
                    break;
                case 38:
                    template38.simpleShape(red,shape,data);
                    break;
                case 39:
                    template39.simpleShape(red,shape,data);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            logService.setDataLogStatus("ppt-error");
            log.error("替换箭头异常，异常页码:{},error:{}",page+1,e);
        }
    }

    public void replaceTable(int page, XSLFShape shape, JsonNode data, XSLFSlide slide) {
        try {
            switch (page+1){
                case 7:
                    template7.table(shape,data);
                    break;
                case 8:
                    template8.table(shape,data);
                    break;
                case 10:
                    template10.table(shape,data,slide);
                    break;
                case 11:
                    template11.table(shape,data,slide);
                    break;
                case 12:
                    template12.table(shape,data);
                    break;
                case 17:
                    template17.table(shape,data);
                    break;
                case 20:
                    template20.table(shape,data);
                    break;
                case 34:
                    template34.table(shape,data);
                    break;
                case 35:
                    template35.table(shape,data);
                    break;
                case 38:
                    template38.table(shape,data);
                    break;
                case 39:
                    template39.table(shape,data);
                    break;
                case 45:
                    template45.table(shape,data);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            logService.setDataLogStatus("ppt-error");
            log.error("表格替换异常，异常页码:{},异常原因:{}",page+1,e);
//            System.exit(0);
        }
    }

    public void replaceBarChart(int page, CTPlotArea plot, JsonNode data, XSSFWorkbook workbook, XSSFSheet sheet, XSLFChart chart) {
        try {
            switch (page+1){
                case 7:
                    template7.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 8:
                    template8.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 9:
                    template9.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 14:
                    template14.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 15:
                    template15.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 18:
                    template18.barChart(plot,data,workbook,sheet,chart);
                    break;
//                case 20:
//                    template20.barChart(plot,data,workbook,sheet,chart);
//                    break;
                case 21:
                    template21.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 22:
                    template22.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 24:
                    template24.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 25:
                    template25.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 27:
                    template27.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 29:
                    template29.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 32:
                    template32.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 35:
                    template35.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 37:
                    template37.barChart(plot,data,workbook,sheet,chart);
                    break;
                case 38:
                    template38.barChart(plot,data,workbook,sheet,chart);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            logService.setDataLogStatus("ppt-error");
            log.error("条形图异常，异常页码:{},异常原因:{}",page+1,e);
        }
    }

    public void replaceLineChart(int page, CTPlotArea plot, JsonNode data, XSSFWorkbook workbook, XSSFSheet sheet, XSLFChart chart) {
        try {
            switch (page+1){
                case 7:
                    template7.lineChart(plot,data,workbook,sheet,chart);
                    break;
                case 14:
                    template14.lineChart(plot,data,workbook,sheet,chart);
                    break;
                case 15:
                    template15.lineChart(plot,data,workbook,sheet,chart);
                    break;
                case 18:
                    template18.lineChart(plot,data,workbook,sheet,chart);
                    break;
//                case 20:
//                    template20.lineChart(plot,data,workbook,sheet,chart);
//                    break;
                case 37:
                    template37.lineChart(plot,data,workbook,sheet,chart);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            logService.setDataLogStatus("ppt-error");
            log.error("折线图异常，异常页码:{}",page+1);
        }
    }

    public void replacePieChart(int page, CTPlotArea plot, JsonNode data, XSSFWorkbook workbook, XSSFSheet sheet, XSLFChart chart) {
        try {
            switch (page+1){
                case 9:
                    template9.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 21:
                    template21.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 22:
                    template22.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 24:
                    template24.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 27:
                    template27.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 29:
                    template29.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 30:
                    template30.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 32:
                    template32.pieChart(plot,data,workbook,sheet,chart);
                    break;
                case 38:
                    template38.pieChart(plot,data,workbook,sheet,chart);
                    break;
                default:
                    break;
            }
        }catch (Exception e){
            logService.setDataLogStatus("ppt-error");
            log.error("饼图异常，异常页码:{},异常原因:{}",page+1,e);
        }
    }
}
